package dao;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.springframework.orm.ibatis.SqlMapClientTemplate;

import util.Utilities;

import dto.AuctionDTO;
import dto.BoardDTO;
import dto.MemberDTO;
import dto.ProductDTO;

public class AuctionDAO {
	private SqlMapClientTemplate sqlMap;

	public AuctionDAO(SqlMapClientTemplate sqlMap) {
		this.sqlMap = sqlMap;
	}
	
	public void insertAuction(AuctionDTO auctionDTO){
		sqlMap.insert("auction.insertAuction", auctionDTO);
	}
	
	public void modifyAuction(AuctionDTO auctionDTO){
		sqlMap.update("auction.modifyAuction", auctionDTO);
	}
	
	public void deleteAuctionByNo(int no){
		sqlMap.delete("auction.deleteAuctionByNo", no);
	}
	
	public AuctionDTO selectAuctionByNo(int no){
		return (AuctionDTO) sqlMap.queryForObject("auction.selectAuctionByNo",no);
	}
	
	public List<AuctionDTO> selectAllAuction(){
		return sqlMap.queryForList("auction.selectAllAuction");
	}

	public int selectMaxAuctionNo() {
		return (Integer) sqlMap.queryForObject("auction.selectMaxAuctionNo");
	}

	public List selectLocations() {
		return sqlMap.queryForList("auction.selectLocations");
	}

	public ArrayList<AuctionDTO> selectAllAuctions() {
		return (ArrayList<AuctionDTO>) sqlMap.queryForList("auction.selectAllAuctions");
	}

	public ArrayList<AuctionDTO> selectAuctionsByMemberId(String id, int page) {
		HashMap<String, Object> map = new HashMap<String, Object>();
		
		map.put("id", id);
		map.put("page", page);
		map.put("contentPerPage", Utilities.CONTENT_PER_PAGE);
		return (ArrayList<AuctionDTO>) sqlMap.queryForList("auction.selectAuctionsByMemberIdAndPage", map);
	}

	public ArrayList<AuctionDTO> selectAuctionsByAuctionName(String auctionName, int page) {
		HashMap<String, Object> map = new HashMap<String, Object>();
		map.put("page", page);
		map.put("contentPerPage", Utilities.CONTENT_PER_PAGE);
		map.put("name", auctionName);
		return (ArrayList<AuctionDTO>) sqlMap.queryForList("auction.selectAuctionsByAuctionName", map);
	}

	public ArrayList<AuctionDTO> selectAuctionsByCategory(String category, int page) {
		HashMap<String, Object> map = new HashMap<String, Object>();
		map.put("page", page);
		map.put("contentPerPage", Utilities.CONTENT_PER_PAGE);
		map.put("category", category);
		return (ArrayList<AuctionDTO>) sqlMap.queryForList("auction.selectAuctionsByCategory", map);
	}

	public ArrayList<AuctionDTO> selectAuctionListByPage(int page) {
		HashMap<String, Integer> map = new HashMap<String, Integer>();
		map.put("page", page);
		map.put("contentPerPage", Utilities.CONTENT_PER_PAGE);
		return (ArrayList<AuctionDTO>) sqlMap.queryForList("auction.selectAuctionListByPage",map);
	}

	public int selectTotalContent() {		
		return (Integer) sqlMap.queryForObject("auction.selectTotalContent");
	}

	public int selectTotalContentByMemberId(String id) {
		return (Integer) sqlMap.queryForObject("auction.selectTotalContentByMemberId", id);
	}

	public ArrayList<String> selectCategoryList() {
		return (ArrayList<String>) sqlMap.queryForList("auction.categoryList");
	}

	public void updateAuction(AuctionDTO auctionDTO) {
		sqlMap.update("auction.updateAuction",auctionDTO);
	}

	public int selectTotalContentByAuctionName(String auctionName) {
		return (Integer) sqlMap.queryForObject("auction.selectTotalContentByAuctionName", auctionName);
	}

	public int selectTotalContentByCategory(String category) {
		return (Integer) sqlMap.queryForObject("auction.selectTotalContentByCategory", category);
	}
}
